namespace hjc {
	export class AStar extends Component {

		private $path: AStarPath;
		private $nodes: AStarNode[];
		private $dir8: Dir8;
		private $flag: number;
		private $init: boolean;
		public get path(): AStarPath { return this.$path; }
		public set path(path: AStarPath) {
			if (this.path !== path) {
				if (this.$path === null && !!path) this.emit(Func.Entity.onStart, path, this.$path);
				else if (!!path) {
					this.emit(Func.Entity.onPathChanged, path, this.$path);
					if (!!this.$entity && !!this.$entity.destin) this.$entity.destin.target = null;
				}
				this.$path = path;
				if (!!path && path.nodes.length > 1) this.$nodes = this.$path.nodes.slice(1);
				else if (!!path) this.$nodes = this.$path.nodes;
			}
		}
		public get dir8(): Dir8 { return this.$dir8; }
		public set dir8(dir8: Dir8) {
			if (this.dir8 !== dir8) {
				this.emit(Func.Entity.onDirChanged, dir8, this.$dir8);
				this.$dir8 = dir8;
			}
		}
		public get flag(): number { return this.$flag; }
		public set flag(flag: number) {
			if (this.flag !== flag) {
				this.emit(Func.Entity.onFlagChanged, flag, this.$flag);
				this.$flag = flag;
			}
		}
		public get nodes(): AStarNode[] { return this.$nodes; }

		public init(path?: AStarPath): void {
			this.$path = null;
			this.$nodes = [];
			this.$dir8 = Dir8.UNKNOWN;
			this.$flag = -1;
			super.resetPfc();
			if (!!path) this.path = path;
		}
	}
}